/*
 * JStatusBar.java
 *
 * Created on March 13, 2006, 9:22 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */
package custom.swing;

import javax.swing.JPanel;
import javax.swing.JLabel;
//import javax.swing.BoxLayout;
import javax.swing.border.Border;
import javax.swing.border.BevelBorder;
import java.awt.GridLayout;

/**
 *
 * @author David Armstrong
 */
public class JStatusBar extends JPanel {

    public static final int SET_ALL_BORDERS = -1;
    private JLabel[] labels = null;

    /** Creates a new instance of JStatusBar */
    public JStatusBar() {
        this(1);
    }

    /** Creates a new instance of JStatusBar */
    public JStatusBar(final int sectionCt) {
        //super();
        labels = new JLabel[sectionCt];
        initialize();
    }

    private void initialize() {
        this.setLayout(new GridLayout(1, labels.length));
        for (int i = 0; i < labels.length; ++i) {
            labels[i] = new JLabel();
            labels[i].setHorizontalAlignment(JLabel.LEFT);
            //labels[i].setBorder(new BevelBorder(BevelBorder.LOWERED));
            this.add(labels[i]);
        }
    }

    public void setMessage(final String text, final int idx) throws ArrayIndexOutOfBoundsException {
        labels[idx].setText(text);
    }

    public String getMessage(final int idx) throws ArrayIndexOutOfBoundsException {
        return (labels[idx].getText());
    }

    public void setBorder(final Border border, final int idx) throws ArrayIndexOutOfBoundsException {
        if (idx == SET_ALL_BORDERS) {
            // Set the border for all JLabels
            for (int i = 0; i < labels.length; ++i) {
                labels[i].setBorder(border);
            }
        } else {
            labels[idx].setBorder(border);
        }
    }
}
